package com.yumei.trader.gym.object;




import com.yumei.trader.gym.view.element.StockHisObject;
import com.yumei.trader.gym.view.element.TicketElement;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Random;

public class GameMapObj extends BaseObj {

    public StockHisObject stock = new StockHisObject();

    @Override
    public void parseJson(JSONObject jsonObj) throws Exception{

        stock.code = jsonObj.optString("symbol");
        stock.name = jsonObj.optString("name");

        JSONArray jsonArr = jsonObj.optJSONArray("items");

        if (jsonArr != null){

            int startIndex = new Random().nextInt(jsonArr.length() - 300);

            for (int i = startIndex; i < startIndex + 300; i++) {

                JSONObject obj = (JSONObject) jsonArr.get(i);

                TicketElement ticketEl = new TicketElement();
                ticketEl.parseJsonOfIntelligence(obj);

                stock.tickets.add(0,ticketEl);
            }
        }
    }
}
